	var APP_CANVAS = null				// Need to set
	var contents = null;				// Need to set
	var allContentsLoaded = null;		// Need to set
	var getContentsUrlCall = null;		// Need to set
	var LOAD_AMOUNT = null;				// Need to set
	var specialLastContent = false;
	var showingBestContents = '1';
	var currentContent = null;
	var loadingContent = false;
	var currentContentIndex = 0;
	var lastIdContent = 0;
	var lastPointsContent = 0;
	var turnPageRight = false;
	var turnPageLeft = false;
	var showingLastContent = false;
	var bestById = true;	// Show best contents ordered by ids or points
	var movesRight = 0;
	var movesLeft = 0;
	var changesToBests = 0;
	var changesToLasts = 0;

	function showBestsContents() {
		if (showingBestContents == '1' || loadingContent == true)
			return;
		
		currentContent = null;
		showingLastContent = false;
		loadingContent = true;
		showingBestContents = '1';
		changesToBests++;
		updateHeaderHrefs();
		spinner.spin(spinnerTarget);
		
		$.post(getContentsUrlCall + "&get_best=" + showingBestContents, {
		}, function(response){
			contentsLoaded(response);

			document.getElementById("bests-button").className = 'right-button-active';
			document.getElementById("lasts-button").className = 'left-button';
		});
	}
	
	function showLastsContents() {
		if (showingBestContents == '0' || loadingContent == true)
			return;
		
		currentContent = null;
		showingLastContent = false;
		loadingContent = true;
		showingBestContents = '0';
		changesToLasts++;
		updateHeaderHrefs();
		spinner.spin(spinnerTarget);
		
		$.post(getContentsUrlCall + "&get_best=" + showingBestContents, {
		}, function(response){
			contentsLoaded(response);

			document.getElementById("bests-button").className = 'right-button';
			document.getElementById("lasts-button").className = 'left-button-active';
			
		});
	}

	function loadContent() {
		if (loadingContent == true)
			return;
			
		loadingContent = true;
		spinner.spin(spinnerTarget);
		
		var callUrl = getContentsUrlCall + "&get_best=" + showingBestContents;

		updateLastIdContent();
		updateLastPointsContent();

		if (showingBestContents == '1' && bestById == false) {
			callUrl = callUrl + "&from_score=" + lastPointsContent;
		} else {
			callUrl = callUrl + "&from_id=" + lastIdContent;
		}

		$.post(callUrl , {
		}, function(response){
			var newContent = JSON.parse(response);
			
			allContentsLoaded = (newContent.length < LOAD_AMOUNT) ? true : false;
			
			contents = contents.concat(newContent);
			updateLastIdContent();
			updateLastPointsContent();
			
			loadingContent = false;
			
			if (turnPageRight == true) {
				turnPageRight = false;
				moveRight();
			}
			
			if (turnPageLeft == true) {
				turnPageLeft = false;
				moveLeft();
			}
			
			spinner.stop();
		});
	}

	function contentsLoaded(response) {
		contents = JSON.parse(response);
		
		allContentsLoaded = (contents.length < LOAD_AMOUNT) ? true : false;
		showMoveArrows();
		
		updateLastIdContent();
		updateLastPointsContent();
		
		currentContentIndex = 0;
		showContentFromList(currentContentIndex);

		spinner.stop();
		loadingContent = false;
	}

	function moveLeft() {
		if (currentContentIndex <= 0 && showingLastContent == false)
			return;
		
		if (showingLastContent) {
			showingLastContent = false;
		} else {
			currentContentIndex--;
		}
		
		showContentFromList(currentContentIndex);
		
		updateComments();
		movesLeft++;
		updateHeaderHrefs();
	}
	
	function moveRight() {
		if (currentContentIndex + 1 >= contents.length) {
			if (allContentsLoaded == true) {

				if (specialLastContent == true)
					showLastContent();
				else
					document.getElementById("next-button").style.display = 'none';

				movesRight++;
				updateHeaderHrefs();
				return;
			}
				
			turnPageRight = true;
			loadContent();
			return;
		}
			
		currentContentIndex++;
		showContentFromList(currentContentIndex);
		
		movesRight++;
		updateHeaderHrefs();

		updateComments();
	}
	
	function showContentFromList(index) {
		if (contents.length > 0 && index < contents.length) {

			if (index == 0)
				document.getElementById("prev-button").style.display = 'none';
			
			if (contents.length > 1)
				document.getElementById("next-button").style.display = '';

			if (index + 1 == contents.length && allContentsLoaded == true)
				document.getElementById("next-button").style.display = 'none';

			content = contents[index];
			
			showContent(content);
		} else {
			showEmptyContents();
		}

		if (index > 0)
			document.getElementById("prev-button").style.display = '';

		if (contents.length <= 1 ) {
			document.getElementById("prev-button").style.display = 'none';
			document.getElementById("next-button").style.display = 'none';
		} 

		if (specialLastContent == true && (index + 1 == contents.length || contents.length == 0) && allContentsLoaded == true && showingLastContent == false)
			document.getElementById("next-button").style.display = '';
	}

	function hideMoveArrows() {
		document.getElementById("prev-button").style.display = 'none';
		document.getElementById("next-button").style.display = 'none';
		
		document.getElementById("bests-button").className = 'right-button';
		document.getElementById("lasts-button").className = 'left-button';
	}
	
	function showMoveArrows() {
		document.getElementById("prev-button").style.display = '';
		document.getElementById("next-button").style.display = '';
	}

	function generateExtraLog() {
		return "movesRight=" + movesRight + ";movesLeft=" + movesLeft + ";changesToBests=" + changesToBests + ";changesToLasts=" + changesToLasts;
	}